//
//  DictToString.m
//  CoreData_1
//
//  Created by liuchengquan on 14-8-13.
//  Copyright (c) 2014年 ChengQuan Liu. All rights reserved.
//

#if __has_feature(objc_arc) 
#define YX_release(obj) 
#define YX_autorelease(obj) 
#else 
#define YX_release(obj) [obj release]
#define YX_autorelease(obj) [obj autorelease] 
#endif
#import "DictToString.h"

@implementation DictToString


+(NSString *)ConvertDictOrArrToString:(id)DictOrArr
{
    if (DictOrArr == nil) {
        return nil ;
    }
    
    NSData *data = [NSJSONSerialization dataWithJSONObject:DictOrArr options:NSJSONWritingPrettyPrinted error:nil];
    if (data == nil) {
        return nil ;
    }
    
    NSString *string = [[NSString alloc ] initWithData:data encoding:NSUTF8StringEncoding];
    
    return string ;
    
}


+(NSData *)ConvertDictOrArrToData:(id)DictOrArr
{
    if (DictOrArr == nil) {
        return  nil ;
    }
    
    NSData * data = [NSJSONSerialization dataWithJSONObject:DictOrArr options:NSJSONWritingPrettyPrinted error:nil];
    return data ;
}


+(id)ConvertStringToDictOrArr:(NSString *)string
{
    if (string == nil) {
        return nil ;
    }
    NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
    
    return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
}


+(id)ConvertDataToDictOrArr:(NSData *)data
{
    
    if (data == nil) {
        return  nil;
    }    
    return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
}
@end
